package com.itheima.server.interceptor;

import com.itheima.tanhua.model.domain.User;

/**
 * ThreadLocal存储数据
 */
public class UserHolder {
    private static ThreadLocal<User> threadLocal = new ThreadLocal<User>();

    /**
     * 存入用户信息到threadlocal
     * @param user
     */
    public static void set(User user){
        threadLocal.set(user);
    }

    /**
     * 获取用户信息
     */
    public static User get(){
       return threadLocal.get();
    }

    /**
     * 获取用户id
     * @return
     */
    public static Long getUserId(){
        return threadLocal.get().getId();
    }
    /**
     * 获取用户手机号
     * @return
     */
    public static String getPhone(){
        return threadLocal.get().getMobile();
    }
    /**
     * 删除threadlocal中的信息
     * @return
     */
    public static void remove(){
        threadLocal.remove();
    }
}
